<?PHP
class webControl
{
	var $attributes = array();
	private $controls = array();

	private $Events = array();

	public $page;
	public function setPage($page)
	{
		$this->page = $page;
	}
	
	function webControl($attrs = array())
	{
		foreach ($attrs as $key => $value)
		{
			$this->attributes[$key] = $value;
		}
	}
	
	function getId()
	{
		if ( isset($this->attributes['id']) )
		{
			return $this->attributes['id'];
		}
		return '';
	}
	function OnInit($sender, $data)
	{
	}
	function Render($writer)
	{
	}
	function RenderOpenTag($writer)
	{
		$writer->Write("<$this->tagName");
	}
	function RenderCloseTag($writer)
	{
		$writer->Write("</$this->tagName>");
	}
	function RenderChildren($writer)
	{
		foreach ( $this->controls as $control )
		{
			$control->Render($writer);
		}
	}
	function addControl($control)
	{
		array_push($this->controls, $control);
	}
	function getControls()
	{
		return $this->controls;
	}
	function findControl($id)
	{
		$context = array( $this );
		while ( count($context) > 0 )
		{
			$curr = array_pop($context);
			foreach ( $curr->controls as $control )
			{
				if ( isset($control->attributes['id']) )
				{
					if ( $id == $control->attributes['id'] )
					{
						return $control;
					}
				}
				array_push($context, $control);
			}
		}
		return false;
	}
	protected function addEvent($key, $event)
	{
		$this->Events[$key] = $event;
	}
	protected function removeEvent($key)
	{
		unset($this->Events[$key]);
	}
	protected function addEventHandler($key, $handler)
	{
		if ( !isset($this->Events[$key]) )
			$this->addEvent($key, new Event());

		$this->Events[$key]->add($handler);
	}
	protected function getEvent($key)
	{
		return $this->Events[$key];
	}
	protected function hasEvent($key)
	{
		return isset($this->Events[$key]);
	}
	protected function removeEventHandler($key, $handler)
	{
		$this->Events[$key].remove($handler);
	}
	function RiseEvents()
	{
	}
}
?>
